﻿package
{
	/**
	 * @author lonely
	 * @date Feb 3, 2013
	 */
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	
	
	/**
	 * TODO 需要调整所有按纽的层级
	 * 重复下注已经是OK的,其它的要调整一下
	 */ 
	public class ButtonList extends MovieClip
	{
		public var btn0:SimpleButton;// 重复和发牌
		
		public var btn1:SimpleButton;// 重复下注
		
		public var btn6:SimpleButton;// 叫牌
		
		public var btn3:SimpleButton;// 发牌1
		
		public var btn7:SimpleButton;// 停止叫牌
		
		public var btn4:SimpleButton;// 双倍
		
		public var btn2:SimpleButton;// 复原1
		
		public var btn5:SimpleButton;// 清除所有下注1
		
		public var btn8:SimpleButton;// 双倍加注1
		
		public var btn9:SimpleButton;// 分牌
		
		public function ButtonList()
		{
			super();	
			this.state = -1;
		}
		
		
		private function visibleButtons():void {
			var count:int = 10;
			for(var i:int = 0; i < count; i++){
				var childName:String = "btn" + i;
				var child:SimpleButton = this[childName];
				child.visible = false;
			}
			
			
		}
		private var _state:int;
		
		/**
		 * 不同的状态显示不同的按纽
		 */ 
		public function set state(value:int):void {
			if(this._state == value){
				return;
			}
			this._state = value;
			switch(this._state){
				case -1:
					this.hide();
					break;
				case 0:
					this.showSecondButton();//如果点击了发牌后显示 叫牌跟 停止叫牌两个啊按钮
					break;
				case 1:
					this.showThredButton();//如果游戏结束了 就显示重复发牌和重复下注
					break;
				case 2:
					this.showDoubleButton();//显示加注按钮
					break;
				case 3:
					this.hideDoubleButton();//隐藏加注按钮
					break;
				case 4:
					this.showFirst();
					break;
				case 5:
					this.showRepeat();// 重复下注和发牌
					break;
				case 6:
					this.splitState();// 分牌按纽的状态
					break;
			}
		}
		//第一组按钮 2,3,5,8
		//第二组按钮 6,7
		//第三组数据0,1;
		//单独的一个4
		
		private function showRepeat():void {
			this.visibleButtons();
			this.btn0.visible = true;
			this.btn1.visible = true;
		}
		
		private function showSecondButton():void
		{
			this.visibleButtons();
			this.btn6.visible = true;
			this.btn7.visible = true;
		}
		
		private function showThredButton():void
		{
			this.visibleButtons();
			this.btn0.visible = true;
			this.btn4.visible = true;	
		}
		
		public function showDoubleButton():void
		{
			this.btn8.visible = true;
		}
		
		public function hideDoubleButton():void
		{
			this.btn8.visible = false;
		}
		
		private function hide():void {
			this.visibleButtons();
		}
		
		private function showFirst():void 
		{
			this.visibleButtons();
			this.btn2.visible = true;
			this.btn3.visible = true;
			this.btn5.visible = true;
			this.btn4.visible = true;
		}
		
		private  function splitState():void {
			this.showSecondButton();
			this.btn9.visible = true;
		}
	}
}